import socket import threading SERVER_IP = '0.0.0.0' SERVER_PORT = "任意のポート番号" # Server port number def handle_client(client_socket): try: data_received = client_socket.recv(1024) print(f"Received: {data_received.decode()}") # Log what was received while data_received: client_socket.send(data_received) # Send the data back to the client data_received = client_socket.recv(1024) except OSError as e: print(f"Error handling client: {e}") finally: client_socket.close() def main(): server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind((SERVER_IP, SERVER_PORT)) server.listen(5) print(f"[*] Listening on {SERVER_IP}:{SERVER_PORT}") while True: client, addr = server.accept() print(f"[*] Accepted connection from: {addr[0]}:{addr[1]}") client_handler = threading.Thread(target=handle_client, args=(client,)) client_handler.start() if __name__ == "__main__": main()